
export default {
  updataPrice (state, data) {
    state.totalPrice = state.totalPrice * data
  },
  priceZero (state, data) {
    state.totalPrice = 0
  },
  setProducts (state, data) {
    state.allGoods = data
  },
  getFruit (state, data) {
    state.allGoods.map(rec => {
      if (rec.id === data.id) {
        rec.nums = parseInt(rec.nums) + 1
        rec.totalPrice = rec.price * rec.nums
      }
    })
  },
  loseFruit (state, data) {
    state.allGoods.map(rec => {
      if (rec.id === data.id) {
        rec.nums = parseInt(rec.nums) - 1
        if (rec.nums <= 0) {
          rec.nums = 0
        }
        rec.totalPrice = rec.price * rec.nums
      }
    })
  },
  setEmpty (state, data) {
    state.allGoods.map(rec => {
      if (rec.id === data.id) {
        rec.nums = 0
        rec.totalPrice = 0
      }
    })
  },
  deleteFruit (state, data) {
    var index = state.allGoods.findIndex(rec => rec.id === data.id)
    if (index > -1) {
      state.allGoods.splice(index, 1)
      return true
    } else {
      return false
    }
  }
}
